package com.example.demo.service;

import com.example.demo.enmus.BookStatusEnums;
import com.example.demo.mapper.BookInfoMapper;
import com.example.demo.model.BookInfo;
import com.example.demo.model.PageRequest;
import com.example.demo.model.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BookService {
    @Autowired
    BookInfoMapper bookInfoMapper;
    public void insertBook(BookInfo bookInfo) {
        bookInfoMapper.insertBook(bookInfo);
    }

    public PageResult<BookInfo> queryBookList(PageRequest pageRequest) {
        Integer total = bookInfoMapper.total();
        List<BookInfo> bookInfoList = bookInfoMapper.queryBookList(pageRequest);
        for (BookInfo bookInfo : bookInfoList) {
            bookInfo.setStatusCN(BookStatusEnums.getDescByCode(bookInfo.getStatus()).getDesc());
        }
        return new PageResult<>(bookInfoList, total, pageRequest);
    }

    public BookInfo queryBookById(Integer bookId) {
        return bookInfoMapper.queryBookById(bookId);
    }

    public Integer updateBook(BookInfo bookInfo) {
        return bookInfoMapper.updateBook(bookInfo);
    }

    public Integer batchDelete(List<Integer> ids) {
        return bookInfoMapper.batchDelete(ids);
    }
}
